using BasicScript.Component;
using Game.Core;
using Game.Main.Model;
using UnityEngine;

namespace Game.Component
{
	public class TyreItem : BaseItem
	{
		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			string value = "tyre_" + base.itemData.tyreId;
			SpriteAssets component = model.GetComponent<SpriteAssets>();
			for (int i = 0; i < component.data.sprites.Count; i++)
			{
				if (component.data.sprites[i].name.Equals(value))
				{
					model.GetComponent<SpriteRenderer>().sprite = component.data.sprites[i];
					break;
				}
			}
		}

		protected override void CheckColls()
		{
			for (int i = 0; i < itemCompColls.Count; i++)
			{
				ItemComponentTrigger.Type type = itemCompColls[i].trigger.type;
				if (type == ItemComponentTrigger.Type.LeftTyre || type == ItemComponentTrigger.Type.RightTyre)
				{
					BaseItem owner = itemCompColls[i].trigger.owner;
					if (owner.itemData.scriptType == 24)
					{
						((CarItem)owner).ChangeTyre(type == ItemComponentTrigger.Type.LeftTyre, base.itemData.tyreId);
						GlobalEventSystem.Fire(new BaseEvent("game.remove_item", archiveData.index));
						return;
					}
				}
			}
			base.CheckColls();
		}
	}
}
